
var fs = require('fs');

exports.getRoot = function(req, res, next){
	
	var ph = req.query.phstr;
	
	console.info("..........."+ph);
	if(ph === undefined){
			ph = "/";
		}
		
		if(fs.existsSync(ph)){
			
					fs.stat(ph,function(err, stats){
					if(stats.isFile()){
							res.download(ph);
						}else{
							
								fs.readdir(ph,function(err,files){
									if(err){
											next(err);
										}else{		
											ph ==='/' ? ph : ph +='/';
											console.info('ph:%s',ph);
											
											res.render('index', { title: 'file server',files :  files,parent : ph});
										}
		});
							
							}
					
					});
			
			
			}else{
					res.render("error");
				
				}
		
		



	
	
	}
